package com.crealth;

import java.util.List;

import org.apache.log4j.Logger;

import com.crealth.db.ConsumerDb;
import com.crealth.manager.MybatisManager;
import com.crealth.memcached.ConsumerCached;
import com.crealth.memcached.MemcachedMgr;
import com.crealth.model.ConsumerInfoModel;
import com.crealth.utils.Utils;

public class UpdateConsumerCliTypeMain {
	private static Logger logger = Logger.getLogger("running_log");
	private static Logger errorLog = Logger.getLogger("error_log");

	public static void main(String[] args) {
		try {
			String osName = Utils.getOSName();
			logger.info("OS: " + osName);
			Config.initConfig();
			MybatisManager.initSessionFactory();
		} catch (Exception e) {
			errorLog.error("init config error", e);
			System.exit(0);
		}

		ConstantDefine.initConstant();
		MemcachedMgr.initMemcached();
		
		String cliType = "13公司成交";
		List<ConsumerInfoModel> consumerls = ConsumerDb.selectAllConsumerInfoByCliType(cliType);
		for (ConsumerInfoModel cjConsumer : consumerls) {
			String phoneNum = cjConsumer.getPhoneNum1();
			List<ConsumerInfoModel> searchPhonels = ConsumerDb.selectConsumerByPhoneNum(phoneNum);
			for (ConsumerInfoModel searchConsumer : searchPhonels) {
				String curClitype = searchConsumer.getCliType();
				if (!curClitype.equals("12本人成交") && 
						!curClitype.equals("13公司成交") ) {
					int consumerID = searchConsumer.getId();
					logger.info("consumerID: " + consumerID + "  " + curClitype);
					ConsumerCached.updateConsumerTypeByID(consumerID, "13公司成交");
				}
			}
		}	
		
		
		logger.info("----      finished    ------------");

	}

}
